/**
 * 
 */
package edu.arizona.bio5.onto.decomposition;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLEntity;

/**
 * @author Pavel Klinov
 *
 */
public abstract class AbstractAtom implements Atom {

	private final Object m_id;
	private final Map<String, Label> m_labels = new HashMap<String, Label>();
	private AxiomSet m_axSet = null;
	
	public AbstractAtom(Object id) {
		
		m_id = id;
	}
	
	public AbstractAtom(Object id, Set<OWLAxiom> axSet) {
		
		this(id);
		m_axSet = new AxiomSet(axSet);
	}
	
	@Override
	public Object getID() {

		return m_id;
	}

	@Override
	public Collection<Label> getLabels() {
		return m_labels.values();
	}
	
	@Override
	public void setLabel(Label label) {
		m_labels.put(label.getType(), label);
	}
	
	@Override
	public void removeLabel(String type) {
		m_labels.remove(type);
	}
	
	@Override
	public Label getLabel(String type) {
		return m_labels.get(type);
	}

	public Set<OWLEntity> getSignature() {
		
		return m_axSet == null ? null : m_axSet.getSignature();
	}
	
	public Set<OWLAxiom> getAxioms() {
		
		return m_axSet == null ? null : m_axSet.getAxioms();
	}
	
	public Set<OWLAxiom> getAllAxioms() {
		
		return m_axSet == null ? null : m_axSet.getAllAxioms();
	}
	
	@Override
	public boolean equals(Object obj) {
		// This instance has mutable content which shouldn't affect hashCode and equals
		return obj instanceof Atom && m_id.equals(((Atom)obj).getID());
	}

	@Override
	public int hashCode() {
		// Same reason as equals
		return m_id.toString().hashCode();
	}
	
	public String toString() {
		
		return m_id.toString();
	}
	
	protected AxiomSet getAxiomSet() {
		
		return m_axSet;
	}
	
	protected void setAxiomSet(Set<OWLAxiom> axioms) {
		
		m_axSet = new AxiomSet(axioms);
	}
}
